package com.sfh.cp.home.child;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sfh.cp.R;
import com.sfh.cp.base.RefreshRecyleFragment;
import com.sfh.cp.home.child.adapter.RankingAdapter;
import com.sfh.cp.home.pst.IPstRanking;
import com.sfh.cp.mass.MassUserActivity;
import com.sfh.cp.widget.WidgetBaseToolbar;
import com.sfh.lib.mvp.IPresenter;
import com.sfh.lib.mvp.service.LoaderService;

import butterknife.BindView;
import crm.sfh.server.entity.EUser;
import crm.sfh.server.entity.req.ReqPage;
import crm.sfh.server.entity.rsp.TPage;

/**
 * 首页-榜单
 */

public class RankingFragment extends RefreshRecyleFragment implements IPstRanking.IVRanking {



    public static RankingFragment newFragment(){
        return new RankingFragment();
    }

    @Override
    public BaseQuickAdapter createAdapter() {
        return new RankingAdapter();
    }

    @Override
    public boolean loadMore() {
        return true;
    }



    int nowPage = 1;
    @Override
    public void onRefreshUI() {
        nowPage =1;
        ReqPage req = new ReqPage(nowPage);
        pstRanking.listPage(req);

    }

    @Override
    public void onLoadMoreUI() {
        nowPage =+1;
        ReqPage req = new ReqPage(nowPage);
        pstRanking.listPage(req);
    }

    IPstRanking pstRanking;

    @Nullable
    @Override
    public IPresenter getPresenter() {
        if (pstRanking == null){
            pstRanking = LoaderService.getService(IPstRanking.class);
        }
        return pstRanking;
    }

    @Override
    public void onSuccess(TPage<EUser> page) {
        success(page);
    }

    @Override
    public void onError(String error) {
        error("",  error);
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

        EUser user = (EUser) adapter.getItem(position);
        MassUserActivity.startUI(getActivity(),user.getUserId());
    }
}
